﻿using DataAccess.DTO;
using DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYD.DataAccess;
using XYD.Framework.Data;
using XYD.Framework.Data.Dapper;

namespace DataAccess.DAL
{
    public class AlimamaDAL : BaseDAL
    {
        public Alimama Get(int id)
        {
            return CONN_TopicSharing.Get<Alimama>(id);
        }

        public bool Insert(Alimama alimama)
        {
            return CONN_TopicSharing.Insert<Alimama>(alimama);
        }

        public bool Update(Alimama alimama)
        {
            return CONN_TopicSharing.Update<Alimama>(alimama);
        }
 
         public List<Alimama> GetAlimamas()
         {
             return CONN_TopicSharing.SQLQuery<Alimama>(" select * from Alimama where is_delete=0 ", null).ToList();
         }

        public List<Alimama> GetAlimamas(string strWhere, string orderbys, int pagesize, int pageindex, out int count,object param)
        {
            List<Alimama> alimamas = new List<Alimama>();
            if (string.IsNullOrEmpty(strWhere))
            {
                strWhere = " is_delete=0 ";
            }

            if (string.IsNullOrEmpty(orderbys))
                orderbys = "id";

            alimamas = CONN_TopicSharing.SQLPager<Alimama>("*", " Alimama", strWhere, "", "", orderbys, pagesize, pageindex, out count, param).ToList();

            return alimamas;
        }

        public bool Exist(string username)
        {
            return CONN_TopicSharing.SQLQuery<int>(string.Format(" select count(1) from Alimama where is_delete=0  and  username='{0}' ", username), null).FirstOrDefault() > 0;
        }

        public bool Exist_alimamaid(string alimamaid)
        {
            return CONN_TopicSharing.SQLQuery<int>(string.Format(" select count(1) from Alimama where is_delete=0  and  alimamaid='{0}' ", alimamaid), null).FirstOrDefault() > 0;
        }

        public List<Alimama> Get_Alimama_List(string promoter_id)
        {
            return CONN_TopicSharing.SQLQuery<Alimama>(" select * from Alimama where is_delete=0  and  promoter_id=@promoter_id ", new { promoter_id = promoter_id }).ToList();
        }
    }
}
